package cn.net.xyan.blossom.webUI.utils

import com.vaadin.ui.AbstractComponent
import org.springframework.web.context.ContextLoader
import org.springframework.web.context.WebApplicationContext

var webApplicationContext: WebApplicationContext? = null

//fun <T> View.getBean(type:Class<T>):T?{
//    val ctx = ContextLoader.getCurrentWebApplicationContext()?:webApplicationContext
//    return ctx?.getBean(type)
//}
//
//fun  View.getBean(name:String):Any?{
//    val ctx = ContextLoader.getCurrentWebApplicationContext()?:webApplicationContext
//    return ctx?.getBean(name)
//}

fun <T> AbstractComponent.getBean(type:Class<T>):T?{
    val ctx = ContextLoader.getCurrentWebApplicationContext()?:webApplicationContext
    return ctx?.getBean(type)
}

fun  AbstractComponent.getBean(name:String):Any?{
    val ctx = ContextLoader.getCurrentWebApplicationContext()?:webApplicationContext
    return ctx?.getBean(name)
}